package argo.hot100.tree;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class MaxDepth {

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int depth = 0;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {

            int size = queue.size();
            for (int i = 0; i < size; i++) {
                root = queue.poll();
                if (root.left != null) {
                    queue.offer(root.left);
                }
                if (root.right != null) {
                    queue.offer(root.right);
                }
            }
            depth++;

        }

        return depth;
    }


    //recursive
    int max = 0;

    public int maxDepthRecu(TreeNode root) {
        maxDepthRecus(root, 1);
        return max;
    }

    public void maxDepthRecus(TreeNode root, int depth) {
        if (root == null) {
            return;
        }
        if (max < depth) {
            max = depth;
        }
        maxDepthRecus(root.left, depth + 1);
        maxDepthRecus(root.right, depth + 1);

    }


}
